package sharemem

import (
	"server_cluster/gate/gate_config"
)
// Index结构全部由GC管理

// Index 全局索引对象
type Index struct {
	User_map map[int64]*User // 玩家map key:uid value:Usr指针
}

// 进程内全局变量
var index_game Index

func GetUserByMapUid(uid int64) *User {
    v,ok := GetUserMap()[uid]
    if !ok {
        return nil
    }
    return v
}

// 活跃用户map
func GetUserMap() map[int64]*User {
	if index_game.User_map == nil {
		index_game.User_map = make(map[int64]*User, gate_config.SHM_USER_MAX)
	}
	return index_game.User_map
}
func SetUserMap(id int64, user *User) {
	GetUserMap()[id] = user
}
func DeleteUserMap(id int64) {
	delete(GetUserMap(), id)
}

// 初始化user map
func Init_all_user_index() {
	var i int32
	for i = 0; i < gate_config.SHM_USER_MAX; i++ {
		if Myshm.User[i].IsUse() {
			SetUserMap(Myshm.User[i].getId(), &(Myshm.User[i]))
		}
	}
}
